function cart_handle_total_default(item) {
    switch (item.nodeName) {
        case 'cost':
        case 'amount':
            $('.so_' + item.nodeName).text(item.textContent);
            break;
    }
}

function handle_number_keys(event) {
    if (event.which < 48 || event.which > 57)
        event.preventDefault();
}

function cart_query(action, itemId, amount, handle_total, handle_item) {
    var url = (content_path ? content_path : '') + '/ajax/cart';
    return $.post(url, {
        action: action,
        itemId: itemId,
        amount: amount
    }).done(function(response) {
        if (response.childNodes && response.childNodes[0].nodeName == 'cart') {
            var cart = response.childNodes[0];
            if (cart.childNodes) {
                for (var i = 0; i < cart.childNodes.length; i++) {
                    var node = cart.childNodes[i];
                    var items = node.childNodes;
                    var j = 0;
                    switch (node.nodeName) {
                        case 'total':
                            if (typeof handle_total != 'function')
                                handle_total = null;
                            for (; j < items.length; j++) {
                                var item = items[j];
                                cart_handle_total_default(item);
                                if (handle_total)
                                    handle_total(item);
                            }
                            break;
                        case 'items':
                            if (handle_item && typeof handle_item == 'function') {
                                for (; j < items.length; j++) {
                                    handle_item(items[j]);
                                }
                            }
                            break;
                    }
                }
            }
        }
    });
}

